package _01_File;
/*
 * FileDemo.java
 *
 * Created on 1 de julio de 2004, 20:33
 */

import java.io.File;

public class FileDemo {
    File dir;
    String path;
    final String ARCHIVO = "datos.txt";
    
    public FileDemo() {
        crearDirectorio();
        crearArchivo();
        eliminarArchivo();
        eliminarDirectorio();
    }
   
    void crearDirectorio() {
    	path = System.getProperty("user.dir")+ File.separator;
        dir = new File(path,"Java");
        if ( !dir.exists() ) dir.mkdirs();
        System.out.println( "---------------------- " );         
        System.out.println( "getAbsolutePath: " + dir.getAbsolutePath() ); 
        System.out.println( "isDirectory: " + dir.isDirectory() ); 
        System.out.println( "---------------------- " ); 
    }    
    
    void crearArchivo() {
        File file = new File(dir, ARCHIVO);
        try {
            file.createNewFile();
            System.out.println( "getName: " + file.getName() );
            System.out.println( "isFile: " + file.isFile() );  
            java.util.Date date = new java.util.Date( file.lastModified() ); 
            System.out.println( "lastModified: " + date.toString() ); 
            System.out.println( "length: " + file.length() ); 
            System.out.println( "---------------------- " );             
        } catch ( java.io.IOException e ) {
            System.out.println( e.getMessage() );
        }        
    }
    
    void eliminarArchivo() {
        File file = new File(dir, ARCHIVO);
        if (file.exists()) {
            file.delete();
            System.out.println( file.toString() + " eliminado" );
            System.out.println( "---------------------- " );              
        }
    }  

    void eliminarDirectorio() {
        if (dir.exists()) {
            dir.delete();
            System.out.println( dir.toString() + "\teliminado" );
        }
    }    
   
    public static void main(String[] args) {
        new FileDemo();
    }
}
